package com.lft.com.oilgas.service.impl;

import com.lft.com.oilgas.entity.Business;
import com.lft.com.oilgas.entity.Merchant;
import com.lft.com.oilgas.mapper.BusinessMapper;
import com.lft.com.oilgas.mapper.MerchantMapper;
import com.lft.com.oilgas.service.IBusinessService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class BusinessServiceImpl implements IBusinessService {
    @Autowired
    private BusinessMapper businessMapper;
    @Autowired
    private MerchantMapper merchantMapper;

    @Override
    public int insterOrUpdateBusiness(Business business) {
        System.out.println(business);
        if (business.getId() != null) {
            return businessMapper.updateById(business);
        } else {
            return businessMapper.insert(business);
        }
    }

    @Override
    public void insterOrgei(Business business) {
        if (business.getId() != null) {
            businessMapper.updateById(business);
        } else {
            businessMapper.insert(business);
            if (business.getSanhuid() != 0) {
                Merchant merchant = merchantMapper.selectById(business.getSanhuid());
                String id = String.valueOf(business.getId());
                merchant.setBusinessLicense(id);
                merchantMapper.updateById(merchant);
            }
        }
    }


    @Override
    public Business selectByid(Integer id) {
        return businessMapper.selectById(id);
    }
}
